﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Inspired.Euler
{
    /// <summary>
    /// The prime factors of 13195 are 5, 7, 13 and 29.
    /// 
    /// What is the largest prime factor of the number 600851475143 ?
    /// </summary>
    public static class Problem003
    {
        /// <summary>
        /// Find the largest prime factor of a composite number.
        /// </summary>
        [EulerProblem(3, Title = "Find the largest prime factor of a composite number.")]
        public static long Solve()
        {
            long number = 600851475143;
            List<long> primes = new List<long>();

            for (int candidate = 2; number > 1; candidate++)
                for (; number % candidate == 0; number /= candidate)
                    primes.Add(candidate);

            return primes.Max();
        }
    }
}
